<template>
  <a-card hoverable :bordered="false" :style="{ width: '100%', marginBottom: '10px' }">
    <div class="xtgg">
      <div class="xtgg_title">
        <div class="xtgg_title_left">系统公告</div>
        <div>
          <div class="btn">一键已读</div>
        </div>
      </div>
      <a-spin :loading="loading" style="width:100%;">
        <a-scrollbar style="height:300px;overflow: auto;" v-if="list.length > 0">
          <div class="xtgg_item" v-for="(item, i) in list" :key="i">
            <div class="xtgg_item_left">
              <div class="xtgg_item_left_r">{{ item.ri }}</div>
              <div class="xtgg_item_left_y">{{ item.yue }}月</div>
            </div>
            <div class="xtgg_item_content">
              {{ item.title }}
            </div>
          </div>
        </a-scrollbar>
        <div v-else style="display:flex; align-items:center;  height: 305px">
          <a-empty />
        </div>
      </a-spin>
      <div style="display:flex;align-items:center; height:20px;">
        <div style="flex:1; font-size:16px; color:#000;">共{{total}}条消息</div>
        <div style="display:flex;align-items:center;">
            <icon-left-circle style="font-size:20px; color:#68C1B2;" @click="pre"/>
            <div style="font-size:16px; margin:0 6px;"> {{searchForm.page}}/{{totalPage}} </div>
            <icon-right-circle style="font-size:20px; color:#68C1B2;" @click="next"/>
        </div>
      </div>
    </div>
  </a-card>
</template>
<script setup>
import { ref, onMounted, reactive } from "vue";
import syApi from "@/api/home/sy";
const loading = ref(false);
const list = ref([]);
const searchForm = reactive({
    page:1,
    pageSize:10
})
onMounted(() => {
  getXtggListPage();
});
const total = ref(0);
const totalPage = ref(0);
const pre = () => { 
    if(searchForm.page == 1){
        return
    }
    searchForm.page--;
    getXtggListPage()
}
const next = () => { 
    if(searchForm.page >= totalPage.value){
        return
    }
    searchForm.page++;
    getXtggListPage()
}
const getXtggListPage = () => {
  loading.value = true;
  syApi
    .getXtggListPage(searchForm)
    .then((res) => {
      if (res.code == 200 && res.success) {
        let items = res.data.items;
        for (let i = 0; i < items.length; i++) {
          let now = new Date(items[i].created_at);
          items[i].yue = String(now.getMonth() + 1).padStart(2, "0");
          items[i].ri = String(now.getDate() + 1).padStart(2, "0");
        }
        list.value = items;
        total.value = res.data.pageInfo.total;
        totalPage.value = res.data.pageInfo.totalPage;
      }
      loading.value = false;
    })
    .catch((e) => {
      console.error(e);
      loading.value = false;
    });
};
</script>
<style scoped lang="less">
.xtgg_title {
  display: flex;
  align-items: center;
  height:40px;
  .xtgg_title_left {
    flex: 1;
    font-family: PingFang SC;
    font-weight: 700;
    font-size: 16px;
    line-height: 100%;
    letter-spacing: 0px;
    color: #000000;
    padding: 2px 10px;
    border-left: 5px solid #68C1B2;
  }
  .btn {
    width: 68;
    height: 28;
    gap: 10px;
    padding-right: 10px;
    padding-left: 10px;
    border-radius: 99px;
    border-width: 1px;
    background: #68C1B226;
    border: 1px solid #68C1B2;
    color: #68C1B2;
  }
}

.xtgg_item {
  display: flex;
  align-items: center;
  margin-top: 15px;
  .xtgg_item_left {
    width: 50px;
    background-color: #f5f5f5;
    margin-right: 10px;
    font-size: 12px;
    border-top: 4px solid #ed4444;
    padding: 2px 0;
    .xtgg_item_left_y {
      font-size: 12px;
      text-align: center;
    }
    .xtgg_item_left_r {
      font-size: 14px;
      text-align: center;
      color: #000;
      font-weight: 600;
    }
  }
  .xtgg_item_content {
    flex: 1;
    font-family: PingFang SC;
    font-weight: 400;
    font-size: 14px;
    line-height: 20px;
    letter-spacing: 0px;
  }
}
</style>
